import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'
import AutoImport from 'unplugin-auto-import/vite'
import Components from '@layui/unplugin-vue-components/vite'
import {LayuiVueResolver} from "@layui/unplugin-vue-components/resolvers";

import httpProxy from 'http-proxy';
// 创建代理服务器对象
const apiProxy = httpProxy.createProxyServer();


// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    vueDevTools(),
    AutoImport({
      resolvers: [LayuiVueResolver()],
    }),
    Components({
      resolvers: [LayuiVueResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    proxy: {
      // 代理的上下文
      '/java': {
        target: 'http://localhost:8088', // 后端服务实际地址
        changeOrigin: true, // 是否改变域名
        rewrite: path => path.replace(/^\/java/, '') // 重写请求路径
      }
    }
  }

})
